# -*- coding: utf-8 -*- 
#
# Description:
#
#  Definiton
#
#
#
# Changes:
#
# 2012-01-10
# Initial Commit
#
#
# Copyright 2010-2012, WyDev Team.
# Author: Polo35 (polo35580@hotmail.fr)
#
# Licenced under Academic Free License version 3.0
# Review WyGui README & LICENSE files for further details.

nname: 125
n 125(None)[]:
	i: 0(AL), 124()
	o: 

nname: 124
n 124(None)[]:
	i: 3(AF), 116()
	o: 125()

nname: 116
n 116(None)[print IFACES
]:
	i: 111(), 115()
	o: 124()

nname: 115
n 115(None)[]:
	i: 16(f)
	o: 116()

nname: 111
n 111(None)[IFACES[c_type.strip('iface_')] = c_name
]:
	i: 61(t), 107()
	o: 116()

nname: 107
n 107(None)[]:
	i: 61(f)
	o: 111()

nname: 61
n 61(c_type.strip('iface_'))[c_type, c_name = line.split('=', 1)
]:
	i: 16(t)
	o: 107(f), 111(t)

nname: 16
n 16(line.lower().startswith('iface'))[for line in file(WYNET_CONF_IN):
line = line.strip()
print 'LINE',
print line
]:
	i: 3(for)
	o: 61(t), 115(f)

nname: 3
n 3(None)[]:
	i: 0(loop)
	o: 16(for), 124(AF)

nname: 0
n 0(None)[]:
	i: 
	o: 3(loop), 125(AL)

nname: 125
n 125(None)[]:
	i: 0(AL), 3(AF), 116()
	o: 

nname: 116
n 116(None)[print IFACES
]:
	i: 61(), 16(f)
	o: 125()

nname: 61
n 61(None)[c_type, c_name = line.split('=', 1)
if not c_type.strip('iface_'):
	pass
IFACES[c_type.strip('iface_')] = c_name
]:
	i: 16(t)
	o: 116()

nname: 16
n 16(line.lower().startswith('iface'))[for line in file(WYNET_CONF_IN):
line = line.strip()
print 'LINE',
print line
]:
	i: 3(for)
	o: 61(t), 116(f)

nname: 3
n 3(None)[]:
	i: 0(loop)
	o: 16(for), 125(AF)

nname: 0
n 0(None)[]:
	i: 
	o: 3(loop), 125(AL)

nname: 125
n 125(None)[]:
	i: 0(AL), 3(AF), 16()
	o: 

nname: 16
n 16(None)[for line in file(WYNET_CONF_IN):
line = line.strip()
print 'LINE',
print line
if line.lower().startswith('iface'):
	c_type, c_name = line.split('=', 1)
	if not c_type.strip('iface_'):
		pass
	IFACES[c_type.strip('iface_')] = c_name
print IFACES
]:
	i: 3(for)
	o: 125()

nname: 3
n 3(None)[]:
	i: 0(loop)
	o: 16(for), 125(AF)

nname: 0
n 0(None)[]:
	i: 
	o: 3(loop), 125(AL)

nname: 16
n 16(None)[for line in file(WYNET_CONF_IN):
	line = line.strip()
	print 'LINE',
	print line
	if line.lower().startswith('iface'):
		c_type, c_name = line.split('=', 1)
		if not c_type.strip('iface_'):
			pass
		IFACES[c_type.strip('iface_')] = c_name
	print IFACES
]:
	i: 0(for)
	o: 

nname: 0
n 0(None)[]:
	i: 
	o: 16(for)

nname: 0
n 0(None)[for line in file(WYNET_CONF_IN):
	line = line.strip()
	print 'LINE',
	print line
	if line.lower().startswith('iface'):
		c_type, c_name = line.split('=', 1)
		if not c_type.strip('iface_'):
			pass
		IFACES[c_type.strip('iface_')] = c_name
	print IFACES
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75b3d4c>}
nname: 123
n 123(None)[]:
	i: 96(), 110(), 121(AE)
	o: 

nname: 121
n 121(None)[]:
	i: 100(f)
	o: 123(AE)

nname: 110
n 110(None)[return False
]:
	i: 100(t)
	o: 123()

nname: 100
n 100(<dummy_ex3> EXC_MATCH IOError)[]:
	i: 0(except)
	o: 110(t), 121(f)

nname: 96
n 96(None)[]:
	i: 3(AL), 95()
	o: 123()

nname: 95
n 95(None)[]:
	i: 6(AF), 91()
	o: 96()

nname: 91
n 91(None)[]:
	i: 19(f), 43()
	o: 95()

nname: 43
n 43(None)[mode = line.split('=', 1)[-1].strip().lower()
return mode == 'upnp'
continue
]:
	i: 19(t)
	o: 91()

nname: 19
n 19(line.lower().startswith('mode'))[for line in file(WYNET_CONF_IN):
]:
	i: 6(for)
	o: 43(t), 91(f)

nname: 6
n 6(None)[]:
	i: 3(loop)
	o: 19(for), 95(AF)

nname: 3
n 3(None)[]:
	i: 0(try)
	o: 6(loop), 96(AL)

nname: 0
n 0(None)[]:
	i: 
	o: 3(try), 100(except)

nname: 123
n 123(None)[]:
	i: 100(), 0(AL), 6(AF), 19()
	o: 

nname: 100
n 100(None)[except IOError:
	return False
]:
	i: 0()
	o: 123()

nname: 123
n 123(None)[]:
	i: 100(), 0(AL), 6(AF), 19()
	o: 

nname: 19
n 19(None)[for line in file(WYNET_CONF_IN):
if line.lower().startswith('mode'):
	mode = line.split('=', 1)[-1].strip().lower()
	return mode == 'upnp'
	continue
]:
	i: 6(for)
	o: 123()

nname: 6
n 6(None)[]:
	i: 0(loop)
	o: 19(for), 123(AF)

nname: 0
n 0(None)[try:
]:
	i: 
	o: 6(loop), 123(AL), 100()

self.nodes: {0: <unpyclib.structure.node instance at 0xb75b502c>, 100: <unpyclib.structure.node instance at 0xb75b5dac>, 6: <unpyclib.structure.node instance at 0xb75b3bec>, 19: <unpyclib.structure.node instance at 0xb75b51cc>, 123: <unpyclib.structure.node instance at 0xb75b3f2c>}
nname: 256
n 256(None)[print 'restarting wynet....'
os.system('/etc/init.d/wynet stop')
os.system('/etc/init.d/wynet start')
]:
	i: 17(AL), 255()
	o: 

nname: 255
n 255(None)[]:
	i: 32(AF), 252()
	o: 256()

nname: 252
n 252(None)[]:
	i: 250(AE)
	o: 255()

nname: 250
n 250(None)[]:
	i: 217(f), 227()
	o: 252(AE)

nname: 227
n 227(None)[log.error('Unable to set the UPNP network configuration -- write error to %s.', out_name)
continue
]:
	i: 217(t)
	o: 250()

nname: 217
n 217(<dummy_ex3> EXC_MATCH IOError)[]:
	i: 39(except), 203()
	o: 227(t), 250(f)

nname: 203
n 203(None)[out_file.close()
continue
]:
	i: 45(AL), 202()
	o: 217()

nname: 202
n 202(None)[]:
	i: 120(AF), 175()
	o: 203()

nname: 175
n 175(None)[out_file.write('iface_%s=%s\n' % (name, val))
]:
	i: 133(f), 154()
	o: 202()

nname: 154
n 154(None)[out_file.write('iface=%s\n' % val)
continue
]:
	i: 133(t)
	o: 175()

nname: 133
n 133(name == 'default')[for name, val in IFACES.iteritems():
]:
	i: 120(for)
	o: 154(t), 175(f)

nname: 120
n 120(None)[]:
	i: 45(loop)
	o: 133(for), 202(AF)

nname: 45
n 45(None)[out_file = open(out_name, 'w')
out_file.write('mode=%s\n' % mode)
out_file.write('address=%s\n' % iface.ip)
out_file.write('netmask=%s\n' % iface.netmask)
]:
	i: 39(try)
	o: 120(loop), 203(AL)

nname: 39
n 39(None)[for out_name in WYNET_CONF_OUTS:
]:
	i: 32(for)
	o: 45(try), 217(except)

nname: 32
n 32(None)[]:
	i: 17(loop)
	o: 39(for), 255(AF)

nname: 17
n 17(None)[mode = 'static'
iface = NetInterface()
]:
	i: 6(), 13()
	o: 32(loop), 256(AL)

nname: 13
n 13(None)[]:
	i: 0(f)
	o: 17()

nname: 6
n 6(None)[]:
	i: 0(t)
	o: 17()

nname: 0
n 0(upnp)[]:
	i: 
	o: 6(t), 13(f)

nname: 256
n 256(None)[print 'restarting wynet....'
os.system('/etc/init.d/wynet stop')
os.system('/etc/init.d/wynet start')
]:
	i: 0(AL), 32(AF), 217(AE)
	o: 

nname: 217
n 217(None)[except IOError:
	log.error('Unable to set the UPNP network configuration -- write error to %s.', out_name)
	continue
]:
	i: 203(), 39()
	o: 256(AE)

nname: 203
n 203(None)[out_file.close()
continue
]:
	i: 39(AL), 120(AF), 133()
	o: 217()

nname: 133
n 133(None)[for name, val in IFACES.iteritems():
if name == 'default':
	out_file.write('iface=%s\n' % val)
	continue
out_file.write('iface_%s=%s\n' % (name, val))
]:
	i: 120(for)
	o: 203()

nname: 120
n 120(None)[]:
	i: 39(loop)
	o: 133(for), 203(AF)

nname: 39
n 39(None)[for out_name in WYNET_CONF_OUTS:
try:
	out_file = open(out_name, 'w')
	out_file.write('mode=%s\n' % mode)
	out_file.write('address=%s\n' % iface.ip)
	out_file.write('netmask=%s\n' % iface.netmask)
]:
	i: 32(for)
	o: 120(loop), 203(AL), 217()

nname: 32
n 32(None)[]:
	i: 0(loop)
	o: 39(for), 256(AF)

nname: 0
n 0(None)[if upnp:
	pass
mode = 'static'
iface = NetInterface()
]:
	i: 
	o: 32(loop), 256(AL)

self.nodes: {0: <unpyclib.structure.node instance at 0xb75b368c>, 32: <unpyclib.structure.node instance at 0xb75b370c>, 133: <unpyclib.structure.node instance at 0xb75b378c>, 39: <unpyclib.structure.node instance at 0xb75b36cc>, 203: <unpyclib.structure.node instance at 0xb75b3dec>, 256: <unpyclib.structure.node instance at 0xb75b3f0c>, 120: <unpyclib.structure.node instance at 0xb75b37cc>, 217: <unpyclib.structure.node instance at 0xb75b390c>}
nname: 129
n 129(None)[return servers
]:
	i: 84(), 114(), 127(AE)
	o: 

nname: 127
n 127(None)[]:
	i: 104(f)
	o: 129(AE)

nname: 114
n 114(None)[servers = []
]:
	i: 104(t)
	o: 129()

nname: 104
n 104(<dummy_ex3> EXC_MATCH IOError)[]:
	i: 0(except)
	o: 114(t), 127(f)

nname: 84
n 84(None)[del _[1]
for servers in resolv:
resolv.close()
]:
	i: 3(AF), 80()
	o: 129()

nname: 80
n 80(None)[]:
	i: 29(f), 47()
	o: 84()

nname: 47
n 47(None)[continue
]:
	i: 29(t)
	o: 80()

nname: 29
n 29(line.startswith('nameserver'))[for line in resolv:
]:
	i: 3(for)
	o: 47(t), 80(f)

nname: 3
n 3(None)[resolv = open(RESOLV_CONF_IN)
]:
	i: 0(try)
	o: 29(for), 84(AF)

nname: 0
n 0(None)[]:
	i: 
	o: 3(try), 104(except)

nname: 129
n 129(None)[return servers
]:
	i: 84(), 104()
	o: 

nname: 104
n 104(None)[except IOError:
	servers = []
]:
	i: 0()
	o: 129()

nname: 84
n 84(None)[del _[1]
for servers in resolv:
resolv.close()
]:
	i: 0(AF), 29()
	o: 129()

nname: 29
n 29(None)[for line in resolv:
if line.startswith('nameserver'):
	continue
]:
	i: 0(for)
	o: 84()

nname: 0
n 0(None)[try:
	resolv = open(RESOLV_CONF_IN)
]:
	i: 
	o: 29(for), 84(AF), 104()

self.nodes: {0: <unpyclib.structure.node instance at 0xb75b322c>, 129: <unpyclib.structure.node instance at 0xb75b5f8c>, 104: <unpyclib.structure.node instance at 0xb75b370c>, 84: <unpyclib.structure.node instance at 0xb75b55ac>, 29: <unpyclib.structure.node instance at 0xb75b31ac>}
nname: 292
n 292(None)[]:
	i: 195(AL), 291()
	o: 

nname: 291
n 291(None)[]:
	i: 198(AF), 288()
	o: 292()

nname: 288
n 288(None)[]:
	i: 286(AE)
	o: 291()

nname: 286
n 286(None)[]:
	i: 253(f), 263()
	o: 288(AE)

nname: 263
n 263(None)[log.error('Unable to set the new DNS server -- write error to %s.', out_name)
continue
]:
	i: 253(t)
	o: 286()

nname: 253
n 253(<dummy_ex3> EXC_MATCH IOError)[]:
	i: 205(except), 211()
	o: 263(t), 286(f)

nname: 211
n 211(None)[out_file = open(out_name, 'w')
out_file.writelines(out)
out_file.close()
continue
]:
	i: 205(try)
	o: 253()

nname: 205
n 205(None)[for out_name in RESOLV_CONF_OUTS:
]:
	i: 198(for)
	o: 211(try), 253(except)

nname: 198
n 198(None)[]:
	i: 195(loop)
	o: 205(for), 291(AF)

nname: 195
n 195(None)[]:
	i: 173(), 194()
	o: 198(loop), 292(AL)

nname: 194
n 194(None)[]:
	i: 159&166(f)
	o: 195()

nname: 173
n 173(None)[out.append('nameserver %s\n' % new)
]:
	i: 159&166(t)
	o: 195()

nname: 159&166
n 159&166(not old and new)[]:
	i: 110(), 134(), 157(AE)
	o: 173(t), 194(f)

nname: 157
n 157(None)[]:
	i: 124(f)
	o: 159&166(AE)

nname: 134
n 134(None)[log.info("%s doesn't exist. Creating it...", RESOLV_CONF_IN)
]:
	i: 124(t)
	o: 159&166()

nname: 124
n 124(<dummy_ex3> EXC_MATCH IOError)[]:
	i: 0(except)
	o: 134(t), 157(f)

nname: 110
n 110(None)[in_file.close()
]:
	i: 9(AL), 109()
	o: 159&166()

nname: 109
n 109(None)[]:
	i: 24(AF), 106()
	o: 110()

nname: 106
n 106(None)[]:
	i: 67(JA), 92()
	o: 109()

nname: 92
n 92(None)[out.append(line)
]:
	i: 31&40(f), 88()
	o: 106()

nname: 88
n 88(None)[continue
]:
	i: 60(f)
	o: 92()

nname: 67
n 67(None)[out.append('nameserver %s\n' % new)
]:
	i: 60(t)
	o: 106(JA)

nname: 60
n 60(new)[]:
	i: 31&40(t)
	o: 67(t), 88(f)

nname: 31&40
n 31&40(old and line.startswith('nameserver %s' % old))[for line in in_file:
]:
	i: 24(for)
	o: 60(t), 92(f)

nname: 24
n 24(None)[]:
	i: 9(loop)
	o: 31&40(for), 109(AF)

nname: 9
n 9(None)[in_file = open(RESOLV_CONF_IN)
]:
	i: 0(try)
	o: 24(loop), 110(AL)

nname: 0
n 0(None)[out = []
]:
	i: 
	o: 9(try), 124(except)

nname: 292
n 292(None)[]:
	i: 159&166(AL), 198(AF), 253(AE)
	o: 

nname: 253
n 253(None)[except IOError:
	log.error('Unable to set the new DNS server -- write error to %s.', out_name)
	continue
]:
	i: 205()
	o: 292(AE)

nname: 205
n 205(None)[for out_name in RESOLV_CONF_OUTS:
try:
	out_file = open(out_name, 'w')
	out_file.writelines(out)
	out_file.close()
	continue
]:
	i: 198(for)
	o: 253()

nname: 198
n 198(None)[]:
	i: 159&166(loop)
	o: 205(for), 292(AF)

nname: 159&166
n 159&166(None)[if not old and new:
	out.append('nameserver %s\n' % new)
]:
	i: 110(), 124()
	o: 198(loop), 292(AL)

nname: 124
n 124(None)[except IOError:
	log.info("%s doesn't exist. Creating it...", RESOLV_CONF_IN)
]:
	i: 0()
	o: 159&166()

nname: 110
n 110(None)[in_file.close()
]:
	i: 0(AL), 24(AF), 67(JA), 92()
	o: 159&166()

nname: 92
n 92(None)[out.append(line)
]:
	i: 31&40(f), 88()
	o: 110()

nname: 88
n 88(None)[continue
]:
	i: 60(f)
	o: 92()

nname: 67
n 67(None)[out.append('nameserver %s\n' % new)
]:
	i: 60(t)
	o: 110(JA)

nname: 60
n 60(new)[]:
	i: 31&40(t)
	o: 67(t), 88(f)

nname: 31&40
n 31&40(old and line.startswith('nameserver %s' % old))[for line in in_file:
]:
	i: 24(for)
	o: 60(t), 92(f)

nname: 24
n 24(None)[]:
	i: 0(loop)
	o: 31&40(for), 110(AF)

nname: 0
n 0(None)[out = []
try:
	in_file = open(RESOLV_CONF_IN)
]:
	i: 
	o: 24(loop), 110(AL), 124()

nname: 292
n 292(None)[]:
	i: 159&166(AL), 198(AF), 205(AE)
	o: 

nname: 205
n 205(None)[for out_name in RESOLV_CONF_OUTS:
try:
	out_file = open(out_name, 'w')
	out_file.writelines(out)
	out_file.close()
	continue
except IOError:
	log.error('Unable to set the new DNS server -- write error to %s.', out_name)
	continue
]:
	i: 198(for)
	o: 292(AE)

nname: 198
n 198(None)[]:
	i: 159&166(loop)
	o: 205(for), 292(AF)

nname: 159&166
n 159&166(None)[if not old and new:
	out.append('nameserver %s\n' % new)
]:
	i: 110(), 124()
	o: 198(loop), 292(AL)

nname: 124
n 124(None)[except IOError:
	log.info("%s doesn't exist. Creating it...", RESOLV_CONF_IN)
]:
	i: 0()
	o: 159&166()

nname: 110
n 110(None)[in_file.close()
]:
	i: 0(AL), 24(AF), 67(JA), 92()
	o: 159&166()

nname: 92
n 92(None)[out.append(line)
]:
	i: 31&40(f), 88()
	o: 110()

nname: 88
n 88(None)[continue
]:
	i: 60(f)
	o: 92()

nname: 67
n 67(None)[out.append('nameserver %s\n' % new)
]:
	i: 60(t)
	o: 110(JA)

nname: 60
n 60(new)[]:
	i: 31&40(t)
	o: 67(t), 88(f)

nname: 31&40
n 31&40(old and line.startswith('nameserver %s' % old))[for line in in_file:
]:
	i: 24(for)
	o: 60(t), 92(f)

nname: 24
n 24(None)[]:
	i: 0(loop)
	o: 31&40(for), 110(AF)

nname: 0
n 0(None)[out = []
try:
	in_file = open(RESOLV_CONF_IN)
]:
	i: 
	o: 24(loop), 110(AL), 124()

self.nodes: {0: <unpyclib.structure.node instance at 0xb75b5bac>, 24: <unpyclib.structure.node instance at 0x9f2942c>, 292: <unpyclib.structure.node instance at 0x9f2956c>, 60: <unpyclib.structure.node instance at 0x9f2952c>, '159&166': <unpyclib.structure.node instance at 0xb75b5e8c>, 67: <unpyclib.structure.node instance at 0x9f292cc>, 198: <unpyclib.structure.node instance at 0x9f293cc>, 205: <unpyclib.structure.node instance at 0xb75b5c0c>, 88: <unpyclib.structure.node instance at 0x9f290ac>, 92: <unpyclib.structure.node instance at 0x9f2986c>, 110: <unpyclib.structure.node instance at 0x9f29a0c>, 124: <unpyclib.structure.node instance at 0xb75b5dcc>, '31&40': <unpyclib.structure.node instance at 0xb75b5fec>}
nname: 0
n 0(None)[self.name = IFACES[_type]
self._ip = None
self._hwaddr = None
self._netmask = None
self._gateway = None
self.update()
return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x9f29f2c>}
nname: 0
n 0(None)[set_upnp(upnp, self)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75b590c>}
nname: 0
n 0(None)[]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75b5fac>}
nname: 496
n 496(None)[return None
]:
	i: 456(), 495()
	o: 

nname: 495
n 495(None)[]:
	i: 444(f)
	o: 496()

nname: 456
n 456(None)[]:
	i: 444(t)
	o: 496()

nname: 444
n 444(data)[del _[2]
for data in raw.split('\n'):
]:
	i: 332(AF), 440()
	o: 456(t), 495(f)

nname: 440
n 440(None)[]:
	i: 392&410(f), 429()
	o: 444()

nname: 429
n 429(None)[continue
]:
	i: 392&410(t)
	o: 440()

nname: 392&410
n 392&410(line.startswith('0.0.0.0 ') and line.endswith(self.name))[for line in raw.split('\n'):
]:
	i: 332(for)
	o: 429(t), 440(f)

nname: 332
n 332(None)[route.close()
]:
	i: 136(AL), 331()
	o: 392&410(for), 444(AF)

nname: 331
n 331(None)[]:
	i: 177(AF), 327()
	o: 332()

nname: 327
n 327(None)[]:
	i: 280(f), 296()
	o: 331()

nname: 296
n 296(None)[continue
]:
	i: 280(t)
	o: 327()

nname: 280
n 280(line.startswith('Mask'))[]:
	i: 233(f), 249()
	o: 296(t), 327(f)

nname: 249
n 249(None)[continue
]:
	i: 233(t)
	o: 280()

nname: 233
n 233(line.startswith('inet addr'))[]:
	i: 184(f), 202()
	o: 249(t), 280(f)

nname: 202
n 202(None)[continue
]:
	i: 184(t)
	o: 233()

nname: 184
n 184(line.startswith('HWaddr'))[for line in fields:
]:
	i: 177(for)
	o: 202(t), 233(f)

nname: 177
n 177(None)[]:
	i: 136(loop)
	o: 184(for), 331(AF)

nname: 136
n 136(None)[]:
	i: 112(), 135()
	o: 177(loop), 332(AL)

nname: 135
n 135(None)[]:
	i: 100(t)
	o: 136()

nname: 112
n 112(None)[raise ValueError('The interface %s does not exist' % self.name)
]:
	i: 100(f)
	o: 136()

nname: 100
n 100(data)[del _[1]
for data in raw.split('\n\n'):
]:
	i: 0(AF), 96()
	o: 112(f), 135(t)

nname: 96
n 96(None)[]:
	i: 60(f), 85()
	o: 100()

nname: 85
n 85(None)[continue
]:
	i: 60(t)
	o: 96()

nname: 60
n 60(line.startswith(self.name + ' '))[for line in raw.split('\n\n'):
]:
	i: 0(for)
	o: 85(t), 96(f)

nname: 0
n 0(None)[ifconfig = os.popen('/sbin/ifconfig')
raw = ifconfig.read()
ifconfig.close()
]:
	i: 
	o: 60(for), 100(AF)

nname: 444
n 444(None)[del _[2]
for data in raw.split('\n'):
if data:
	pass
return None
]:
	i: 332(AF), 392&410(f)
	o: 

nname: 392&410
n 392&410(None)[for line in raw.split('\n'):
if line.startswith('0.0.0.0 ') and line.endswith(self.name):
	continue
]:
	i: 332(for)
	o: 444()

nname: 332
n 332(None)[route.close()
]:
	i: 100(AL), 177(AF), 280()
	o: 392&410(for), 444(AF)

nname: 280
n 280(None)[if line.startswith('Mask'):
	continue
]:
	i: 184(f)
	o: 332()

nname: 184
n 184(None)[for line in fields:
if line.startswith('HWaddr'):
	continue
if line.startswith('inet addr'):
	continue
]:
	i: 177(for)
	o: 280()

nname: 177
n 177(None)[]:
	i: 100(loop)
	o: 184(for), 332(AF)

nname: 100
n 100(None)[del _[1]
for data in raw.split('\n\n'):
if not data:
	raise ValueError('The interface %s does not exist' % self.name)
]:
	i: 0(AF), 60()
	o: 177(loop), 332(AL)

nname: 60
n 60(None)[for line in raw.split('\n\n'):
if line.startswith(self.name + ' '):
	continue
]:
	i: 0(for)
	o: 100()

nname: 0
n 0(None)[ifconfig = os.popen('/sbin/ifconfig')
raw = ifconfig.read()
ifconfig.close()
]:
	i: 
	o: 60(for), 100(AF)

nname: 444
n 444(None)[del _[2]
for data in raw.split('\n'):
if data:
	pass
return None
]:
	i: 332(AF), 392&410(f)
	o: 

nname: 392&410
n 392&410(None)[for line in raw.split('\n'):
if line.startswith('0.0.0.0 ') and line.endswith(self.name):
	continue
]:
	i: 332(for)
	o: 444()

nname: 332
n 332(None)[route.close()
]:
	i: 100(AL), 177(AF), 184()
	o: 392&410(for), 444(AF)

nname: 184
n 184(None)[for line in fields:
if line.startswith('HWaddr'):
	continue
if line.startswith('inet addr'):
	continue
if line.startswith('Mask'):
	continue
]:
	i: 177(for)
	o: 332()

nname: 177
n 177(None)[]:
	i: 100(loop)
	o: 184(for), 332(AF)

nname: 100
n 100(None)[del _[1]
for data in raw.split('\n\n'):
if not data:
	raise ValueError('The interface %s does not exist' % self.name)
]:
	i: 0(AF), 60()
	o: 177(loop), 332(AL)

nname: 60
n 60(None)[for line in raw.split('\n\n'):
if line.startswith(self.name + ' '):
	continue
]:
	i: 0(for)
	o: 100()

nname: 0
n 0(None)[ifconfig = os.popen('/sbin/ifconfig')
raw = ifconfig.read()
ifconfig.close()
]:
	i: 
	o: 60(for), 100(AF)

self.nodes: {0: <unpyclib.structure.node instance at 0x9f2e8ac>, 444: <unpyclib.structure.node instance at 0x9f2efcc>, 177: <unpyclib.structure.node instance at 0x9f2ec0c>, 60: <unpyclib.structure.node instance at 0x9f2ee6c>, '392&410': <unpyclib.structure.node instance at 0x9f2e8ec>, 332: <unpyclib.structure.node instance at 0x9f2e9ac>, 184: <unpyclib.structure.node instance at 0x9f2edcc>, 100: <unpyclib.structure.node instance at 0x9f2ecac>}
nname: 67
n 67(None)[]:
	i: 34(), 57()
	o: 

nname: 57
n 57(None)[self._ip = ip
]:
	i: 0(f)
	o: 67()

nname: 34
n 34(None)[log.error('Unable to set the IP adress for %s', self.name)
]:
	i: 0(t)
	o: 67()

nname: 0
n 0(os.system(commmand))[commmand = '/sbin/ifconfig %s %s' % (self.name, ip)
]:
	i: 
	o: 34(t), 57(f)

nname: 0
n 0(None)[commmand = '/sbin/ifconfig %s %s' % (self.name, ip)
if os.system(commmand):
	log.error('Unable to set the IP adress for %s', self.name)
else:
	self._ip = ip
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x9f29b0c>}
nname: 67
n 67(None)[]:
	i: 34(), 57()
	o: 

nname: 57
n 57(None)[self._netmask = netmask
]:
	i: 0(f)
	o: 67()

nname: 34
n 34(None)[log.error('Unable to set the netmask for %s', self.name)
]:
	i: 0(t)
	o: 67()

nname: 0
n 0(os.system(command))[command = '/sbin/ifconfig %s netmask %s' % (self.name, netmask)
]:
	i: 
	o: 34(t), 57(f)

nname: 0
n 0(None)[command = '/sbin/ifconfig %s netmask %s' % (self.name, netmask)
if os.system(command):
	log.error('Unable to set the netmask for %s', self.name)
else:
	self._netmask = netmask
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x9f29cac>}
nname: 109
n 109(None)[]:
	i: 47(), 99()
	o: 

nname: 99
n 99(None)[self._gateway = gateway
]:
	i: 0(f)
	o: 109()

nname: 47
n 47(None)[log.error('Unable to set the gateway for %s', self.name)
os.system('/sbin/route add default gw %s dev %s' % (self._gateway, self.name))
]:
	i: 0(t)
	o: 109()

nname: 0
n 0(os.system(command))[os.system('/sbin/route del default')
command = '/sbin/route add default gw %s dev %s' % (gateway, self.name)
]:
	i: 
	o: 47(t), 99(f)

nname: 0
n 0(None)[os.system('/sbin/route del default')
command = '/sbin/route add default gw %s dev %s' % (gateway, self.name)
if os.system(command):
	log.error('Unable to set the gateway for %s', self.name)
	os.system('/sbin/route add default gw %s dev %s' % (self._gateway, self.name))
else:
	self._gateway = gateway
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x9f2978c>}
nname: 30
n 30(None)[return False
]:
	i: 19(), 26()
	o: 

nname: 26
n 26(None)[]:
	i: 0(f)
	o: 30()

nname: 19
n 19(None)[]:
	i: 0(t)
	o: 30()

nname: 0
n 0(self.ip)[self.update()
]:
	i: 
	o: 19(t), 26(f)

nname: 0
n 0(None)[self.update()
if self.ip:
	pass
return False
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x9f29fac>}
nname: 0
n 0(None)[return self._ip
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x9f290ac>}
nname: 0
n 0(None)[return self._ip
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x9f29bac>}
nname: 0
n 0(None)[return self._netmask
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x9f29dec>}
nname: 0
n 0(None)[return self._netmask
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x9f29fac>}
nname: 0
n 0(None)[return self._hwaddr
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x9f290ac>}
nname: 0
n 0(None)[return self._hwaddr
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x9f2962c>}
nname: 0
n 0(None)[return self._gateway
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x9f2964c>}
nname: 0
n 0(None)[return self._gateway
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x9f29a0c>}
nname: 0
n 0(None)[return self._check_connected
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x9f2910c>}
nname: 0
n 0(None)[return self._check_connected
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x9f2962c>}
nname: 0
n 0(None)[return 'NetInterface <%s (%s)>' % (self.name, self.ip)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x9f29cac>}
nname: 6
n 6(None)[__doc__ = 'Wrapper around a system network interface.'
def __init__(self, _type='wired'):
	self.name = IFACES[_type]
	self._ip = None
	self._hwaddr = None
	self._netmask = None
	self._gateway = None
	self.update()
	return None

def save(self, upnp=True):
	set_upnp(upnp, self)

def stop(self):
	pass

def update(self):
	ifconfig = os.popen('/sbin/ifconfig')
	raw = ifconfig.read()
	ifconfig.close()

def _set_ip(self, ip):
	commmand = '/sbin/ifconfig %s %s' % (self.name, ip)
	if os.system(commmand):
		log.error('Unable to set the IP adress for %s', self.name)
	else:
		self._ip = ip

def _set_netmask(self, netmask):
	command = '/sbin/ifconfig %s netmask %s' % (self.name, netmask)
	if os.system(command):
		log.error('Unable to set the netmask for %s', self.name)
	else:
		self._netmask = netmask

def _set_gateway(self, gateway):
	os.system('/sbin/route del default')
	command = '/sbin/route add default gw %s dev %s' % (gateway, self.name)
	if os.system(command):
		log.error('Unable to set the gateway for %s', self.name)
		os.system('/sbin/route add default gw %s dev %s' % (self._gateway, self.name))
	else:
		self._gateway = gateway

def _check_connected(self):
	self.update()
	if self.ip:
		pass
	return False

ip = property((lambda self: self._ip), _set_ip, None, 'IP Address.')
netmask = property((lambda self: self._netmask), _set_netmask, None, 'Subnet mask.')
hwaddr = property((lambda self: self._hwaddr), None, None, 'Hardware (MAC) address. Cannot be changed.')
gateway = property((lambda self: self._gateway), _set_gateway, None, 'Default gateway.')
connected = property((lambda self: self._check_connected), None, None, 'is this interface working ?')
def __repr__(self):
	return 'NetInterface <%s (%s)>' % (self.name, self.ip)

]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb75b3acc>}
nname: 0
n 0(None)[NetInterface.__init__(self, 'wireless')
self.networks = list()
self.selected_net = None
self.key_type = None
self.private_key = None
return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x9f297ec>}
nname: 0
n 0(None)[self.networks.append(dict(name='Wifi-1', signal=62, security=True, rate=54))
self.networks.append(dict(name='Wifi-2', signal=96, security=True, rate=54))
self.networks.append(dict(name='Wifi-3', signal=17, security=True, rate=54))
self.networks.append(dict(name='Wifi-4', signal=80, security=True, rate=54))
self.networks.append(dict(name='Wifi-5', signal=54, security=True, rate=54))
self.networks.append(dict(name='Wifi-6', signal=38, security=False, rate=11))
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75b512c>}
nname: 6
n 6(None)[def __init__(self):
	NetInterface.__init__(self, 'wireless')
	self.networks = list()
	self.selected_net = None
	self.key_type = None
	self.private_key = None
	return None

def scan(self):
	self.networks.append(dict(name='Wifi-1', signal=62, security=True, rate=54))
	self.networks.append(dict(name='Wifi-2', signal=96, security=True, rate=54))
	self.networks.append(dict(name='Wifi-3', signal=17, security=True, rate=54))
	self.networks.append(dict(name='Wifi-4', signal=80, security=True, rate=54))
	self.networks.append(dict(name='Wifi-5', signal=54, security=True, rate=54))
	self.networks.append(dict(name='Wifi-6', signal=38, security=False, rate=11))

]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0x9f297ac>}
nname: 0
n 0(None)[__doc__ = 'Wybox network configuration. Wraps (currently throwaway) calls to the system\nnetwork configuration APIs.'
from __future__ import absolute_import
import os
from .debug import GET_LOGGER
log = GET_LOGGER('network')
RESOLV_CONF_IN = '/etc/params/resolv.conf'
RESOLV_CONF_OUTS = [RESOLV_CONF_IN]
WYNET_CONF_IN = '/etc/params/wynet.conf'
WYNET_CONF_OUTS = [WYNET_CONF_IN]
IFACES = dict()
def read_config():
	for line in file(WYNET_CONF_IN):
		line = line.strip()
		print 'LINE',
		print line
		if line.lower().startswith('iface'):
			c_type, c_name = line.split('=', 1)
			if not c_type.strip('iface_'):
				pass
			IFACES[c_type.strip('iface_')] = c_name
		print IFACES

def is_upnp():
	try:

def set_upnp(upnp):
	if upnp:
		pass
	mode = 'static'
	iface = NetInterface()

def dns_servers():
	try:
		resolv = open(RESOLV_CONF_IN)

def replace_dns(old, new):
	out = []
	try:
		in_file = open(RESOLV_CONF_IN)

class NetInterface(object):
	__doc__ = 'Wrapper around a system network interface.'
	def __init__(self, _type='wired'):
		self.name = IFACES[_type]
		self._ip = None
		self._hwaddr = None
		self._netmask = None
		self._gateway = None
		self.update()
		return None

	def save(self, upnp=True):
		set_upnp(upnp, self)

	def stop(self):
		pass

	def update(self):
		ifconfig = os.popen('/sbin/ifconfig')
		raw = ifconfig.read()
		ifconfig.close()

	def _set_ip(self, ip):
		commmand = '/sbin/ifconfig %s %s' % (self.name, ip)
		if os.system(commmand):
			log.error('Unable to set the IP adress for %s', self.name)
		else:
			self._ip = ip

	def _set_netmask(self, netmask):
		command = '/sbin/ifconfig %s netmask %s' % (self.name, netmask)
		if os.system(command):
			log.error('Unable to set the netmask for %s', self.name)
		else:
			self._netmask = netmask

	def _set_gateway(self, gateway):
		os.system('/sbin/route del default')
		command = '/sbin/route add default gw %s dev %s' % (gateway, self.name)
		if os.system(command):
			log.error('Unable to set the gateway for %s', self.name)
			os.system('/sbin/route add default gw %s dev %s' % (self._gateway, self.name))
		else:
			self._gateway = gateway

	def _check_connected(self):
		self.update()
		if self.ip:
			pass
		return False

	ip = property((lambda self: self._ip), _set_ip, None, 'IP Address.')
	netmask = property((lambda self: self._netmask), _set_netmask, None, 'Subnet mask.')
	hwaddr = property((lambda self: self._hwaddr), None, None, 'Hardware (MAC) address. Cannot be changed.')
	gateway = property((lambda self: self._gateway), _set_gateway, None, 'Default gateway.')
	connected = property((lambda self: self._check_connected), None, None, 'is this interface working ?')
	def __repr__(self):
		return 'NetInterface <%s (%s)>' % (self.name, self.ip)



class WifiInterface(NetInterface):
	def __init__(self):
		NetInterface.__init__(self, 'wireless')
		self.networks = list()
		self.selected_net = None
		self.key_type = None
		self.private_key = None
		return None

	def scan(self):
		self.networks.append(dict(name='Wifi-1', signal=62, security=True, rate=54))
		self.networks.append(dict(name='Wifi-2', signal=96, security=True, rate=54))
		self.networks.append(dict(name='Wifi-3', signal=17, security=True, rate=54))
		self.networks.append(dict(name='Wifi-4', signal=80, security=True, rate=54))
		self.networks.append(dict(name='Wifi-5', signal=54, security=True, rate=54))
		self.networks.append(dict(name='Wifi-6', signal=38, security=False, rate=11))



read_config()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75a9cac>}
__doc__ = 'Wybox network configuration. Wraps (currently throwaway) calls to the system\nnetwork configuration APIs.'
from __future__ import absolute_import
import os
from .debug import GET_LOGGER
log = GET_LOGGER('network')
RESOLV_CONF_IN = '/etc/params/resolv.conf'
RESOLV_CONF_OUTS = [RESOLV_CONF_IN]
WYNET_CONF_IN = '/etc/params/wynet.conf'
WYNET_CONF_OUTS = [WYNET_CONF_IN]
IFACES = dict()
def read_config():
	for line in file(WYNET_CONF_IN):
		line = line.strip()
		print 'LINE',
		print line
		if line.lower().startswith('iface'):
			c_type, c_name = line.split('=', 1)
			if not c_type.strip('iface_'):
				pass
			IFACES[c_type.strip('iface_')] = c_name
		print IFACES

def is_upnp():
	try:

def set_upnp(upnp):
	if upnp:
		pass
	mode = 'static'
	iface = NetInterface()

def dns_servers():
	try:
		resolv = open(RESOLV_CONF_IN)

def replace_dns(old, new):
	out = []
	try:
		in_file = open(RESOLV_CONF_IN)

class NetInterface(object):
	__doc__ = 'Wrapper around a system network interface.'
	def __init__(self, _type='wired'):
		self.name = IFACES[_type]
		self._ip = None
		self._hwaddr = None
		self._netmask = None
		self._gateway = None
		self.update()
		return None

	def save(self, upnp=True):
		set_upnp(upnp, self)

	def stop(self):
		pass

	def update(self):
		ifconfig = os.popen('/sbin/ifconfig')
		raw = ifconfig.read()
		ifconfig.close()

	def _set_ip(self, ip):
		commmand = '/sbin/ifconfig %s %s' % (self.name, ip)
		if os.system(commmand):
			log.error('Unable to set the IP adress for %s', self.name)
		else:
			self._ip = ip

	def _set_netmask(self, netmask):
		command = '/sbin/ifconfig %s netmask %s' % (self.name, netmask)
		if os.system(command):
			log.error('Unable to set the netmask for %s', self.name)
		else:
			self._netmask = netmask

	def _set_gateway(self, gateway):
		os.system('/sbin/route del default')
		command = '/sbin/route add default gw %s dev %s' % (gateway, self.name)
		if os.system(command):
			log.error('Unable to set the gateway for %s', self.name)
			os.system('/sbin/route add default gw %s dev %s' % (self._gateway, self.name))
		else:
			self._gateway = gateway

	def _check_connected(self):
		self.update()
		if self.ip:
			pass
		return False

	ip = property((lambda self: self._ip), _set_ip, None, 'IP Address.')
	netmask = property((lambda self: self._netmask), _set_netmask, None, 'Subnet mask.')
	hwaddr = property((lambda self: self._hwaddr), None, None, 'Hardware (MAC) address. Cannot be changed.')
	gateway = property((lambda self: self._gateway), _set_gateway, None, 'Default gateway.')
	connected = property((lambda self: self._check_connected), None, None, 'is this interface working ?')
	def __repr__(self):
		return 'NetInterface <%s (%s)>' % (self.name, self.ip)



class WifiInterface(NetInterface):
	def __init__(self):
		NetInterface.__init__(self, 'wireless')
		self.networks = list()
		self.selected_net = None
		self.key_type = None
		self.private_key = None
		return None

	def scan(self):
		self.networks.append(dict(name='Wifi-1', signal=62, security=True, rate=54))
		self.networks.append(dict(name='Wifi-2', signal=96, security=True, rate=54))
		self.networks.append(dict(name='Wifi-3', signal=17, security=True, rate=54))
		self.networks.append(dict(name='Wifi-4', signal=80, security=True, rate=54))
		self.networks.append(dict(name='Wifi-5', signal=54, security=True, rate=54))
		self.networks.append(dict(name='Wifi-6', signal=38, security=False, rate=11))



read_config()
